package cn.edu.zjgsu.ito.controller;

import java.util.List;

import cn.edu.zjgsu.ito.interceptor.TeacherControllerInterceptor;
import cn.edu.zjgsu.ito.service.ServiceFactory;
import cn.edu.zjgsu.ito.service.TeaTimetableService;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

@Before(TeacherControllerInterceptor.class)
public class TeaTimeTableController extends Controller{
	/*
	 * 张虎涛
	 * 2016/06/01
	 */
	private TeaTimetableService teaTimetableService =ServiceFactory.createTeaTimetableServiceService();
	private String tNo;
	private List<Record> termValues;
	private List<Record> Record;
	public void index(){
         System.out.println(termValues);
		if(getSessionAttr("tNo")==null){
			System.out.println("登录超时，请从新登陆！");
			render("../common/errors/outlogin.html");
			return;
		}else{
			tNo=getSessionAttr("tNo");
		}
				
		termValues=teaTimetableService.Term(tNo);
        System.out.println(tNo);
        System.out.println(termValues);
		setAttr("termValues",termValues);
		render("myTimeTable.html");
	}
	public void getKb(){
		String termValue=getPara("termValue");
		tNo=getSessionAttr("tNo");
        System.out.println("来这里了么？");
		Record=teaTimetableService.TTT(tNo,termValue);
        System.out.println(Record);

		renderJson(Record);
	}
	
	public void search(){
		if(getSessionAttr("tNo")==null){
			render("../../common/errors/outlogin.html");
			return;
		}else{
			tNo=getSessionAttr("tNo");
		}
		String termValue=getPara("termValue");
		Record=teaTimetableService.TTT(tNo,termValue);
		
		if(Record==null){
			setAttr("message", "系统错误"); 
			redirect("/toErrors");
			return;
		}else{
			termValues=teaTimetableService.Term(tNo);
			setAttr("record",Record);
			setAttr("termValues",termValues);
			render("myTimeTable.html");
			
		}
	}

}
